////////////////////////////////////////////////
// File: NewsService.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:33
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.service;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mvc.dao.EntityDao;
import com.mvc.entity.News;
import com.pub.Page;

@Service
public class  NewsService {
	@Autowired
	private EntityDao entityDao;

	@Transactional
	public List<Object> getNewsList(String hql, Page page) {
		List<Object> list = entityDao.pageQuery(hql, page.getPageNo(),
				page.getPageSize());
		return list;
	}

	public int getCount(String hql, Page page) {
		int count = 0;
		count = entityDao.countQuery(hql);
		if ((count % page.getPageSize()) == 0) {
			count = count / page.getPageSize();
		}else
		{
			count = count / page.getPageSize() + 1;
		}
		return count;
	}

	public void Save( News  news) {
		entityDao.save(news);
	}

	public void EditSave(News news) {
		entityDao.saveOrUpdate(news);
	}

	public void Del(String ID) {
		entityDao.delById(News.class, Integer.parseInt(ID));
	}

	public News getNewsByHql(String hql) {
		News news = (News) entityDao.loadObject(hql);
		return news;
	}
    
   public News getNews(String ID){
	   News news=(News) entityDao.loadById(News.class,Integer.valueOf(ID));
	   return news;
      }
	public List<Object> getListByHql(String hql) {
		List<Object> list = entityDao.query(hql);
		return list;
	}

}
